package com.dican.portal.pedidos;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.dican.portal.DAO.ProdutoDAO;
import com.dican.portal.beans.Representante;

public class fillProd extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public fillProd() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Representante rep = new Representante();
		HttpSession session = request.getSession(false);
		if(session==null)
			response.sendRedirect("logout.jsp");
		else{
			Integer prodCod = Integer.parseInt(request.getParameter("prodCod"));
			rep = (Representante)session.getAttribute("rep");
			PrintWriter out = response.getWriter();
			try{
				session.setAttribute("detalheProd", ProdutoDAO.getProduto(rep.getOrgid(),prodCod.toString()));
			}catch(SQLException e){
					out.print("SQL error "+e.getMessage());
			}catch(Exception e){
					out.print("Erro no FillProduto.<br>Contate o Suporte da Dican e informe o seguinte erro:<br>"+e.getMessage());
			}
		}
	}

}
